package cn.edu.nuc.android.oweibo.activities;

import weibo4android.Status;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import cn.edu.nuc.android.oweibo.R;

public class StatusDetailActivity extends Activity {

	public static final String STATUS = "status";

	private TextView userNameText;
	private TextView statusText;
	private TextView createdAtText;
	private TextView replyToText;
	private TextView geoText;

	private Status status;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.status_detail);
		setUpViews();
		status = (Status) getIntent().getSerializableExtra(STATUS);
		showStatus();
	}
	

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return MenuHelper.openActivityFromMenuItem(this, item);
	}

	/**
	 * 产生menu项
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}

	private void showStatus() {
		userNameText.setText(status.getUser().getName());
		statusText.setText(status.getText());
		
		String createAt = getResources().getString(R.string.created_at_format, status.getCreatedAt().toLocaleString());
		createdAtText.setText(createAt);
		
		if (null != status.getInReplyToScreenName()) {
			String replyTo = getResources().getString(R.string.in_reply_to_format, status.getInReplyToScreenName());
			replyToText.setText(replyTo);
			replyToText.setVisibility(View.VISIBLE);
		}
		
	}

	private void setUpViews() {
		userNameText = (TextView) findViewById(R.id.status_user_name_text);
		statusText = (TextView) findViewById(R.id.status_text);
		createdAtText = (TextView) findViewById(R.id.created_at_text);
		replyToText = (TextView) findViewById(R.id.reply_to_text);
		geoText = (TextView) findViewById(R.id.geo_text);
	}
	
}
